home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / src / mod_userdir.c < prev    next >
Text File  |  1995-12-04  |  5KB  |  144 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * mod_userdir... implement the UserDir command.  Broken away from the
  57.  * Alias stuff for a couple of good and not-so-good reasons:
  58.  *
  59.  * 1) It shows a real minimal working example of how to do something like
  60.  *    this.
  61.  * 2) I know people who are actually interested in changing this *particular*
  62.  *    aspect of server functionality without changing the rest of it.  That's
  63.  *    what this whole modular arrangement is supposed to be good at...
  64.  */
  65.  
  66. #include "httpd.h"
  67. #include "http_config.h"
  68.  
  69. module userdir_module;
  70.  
  71. /*
  72.  * Sever config for this module is a little unconventional...
  73.  * It's just one string anyway, so why pretend?
  74.  */
  75.  
  76. void *create_userdir_config (pool *dummy, server_rec *s) { 
  77.     return (void*)DEFAULT_USER_DIR; 
  78. }
  79.  
  80. char *set_user_dir (cmd_parms *cmd, void *dummy, char *arg)
  81. {
  82.     void *server_conf = cmd->server->module_config;
  83.     
  84.     set_module_config (server_conf, &userdir_module, pstrdup (cmd->pool, arg));
  85.     return NULL;
  86. }
  87.  
  88. command_rec userdir_cmds[] = {
  89. { "UserDir", set_user_dir, NULL, RSRC_CONF, TAKE1,
  90.     "the public subdirectory in users' home directories, or 'disabled'" },
  91. { NULL }
  92. };
  93.  
  94. int translate_userdir (request_rec *r)
  95. {
  96.     void *server_conf = r->server->module_config;
  97.     char *userdir = (char *)get_module_config(server_conf, &userdir_module);
  98.     char *name = r->uri;
  99.     
  100.     if (userdir != NULL && strcasecmp(userdir, "disabled") != 0 &&
  101.     name[0] == '/' && name[1] == '~')
  102.     {
  103.         struct passwd *pw;
  104.     char *w, *dname;
  105.  
  106.         dname = name + 2;
  107.         w = getword(r->pool, &dname, '/');
  108.         if(!(pw=getpwnam(w)))
  109.             return NOT_FOUND;
  110.     
  111.     /* The 'dname' funny business involves backing it up to capture
  112.      * the '/' delimiting the "/~user" part from the rest of the URL,
  113.      * in case there was one (the case where there wasn't being just
  114.      * "GET /~user HTTP/1.0", for which we don't want to tack on a
  115.      * '/' onto the filename).
  116.      */
  117.     
  118.     if (dname[-1] == '/') --dname;
  119.     r->filename = pstrcat (r->pool, pw->pw_dir, "/", userdir, dname, NULL);
  120.  
  121.     return OK;
  122.     }
  123.  
  124.     return DECLINED;
  125. }
  126.     
  127. module userdir_module = {
  128.    STANDARD_MODULE_STUFF,
  129.    NULL,            /* initializer */
  130.    NULL,            /* dir config creater */
  131.    NULL,            /* dir merger --- default is to override */
  132.    create_userdir_config,    /* server config */
  133.    NULL,            /* merge server config */
  134.    userdir_cmds,        /* command table */
  135.    NULL,            /* handlers */
  136.    translate_userdir,        /*filename translation */
  137.    NULL,            /* check_user_id */
  138.    NULL,            /* check auth */
  139.    NULL,            /* check access */
  140.    NULL,            /* type_checker */
  141.    NULL,            /* fixups */
  142.    NULL                /* logger */
  143. };
  144.